package com.example.demo.threadpool;

import java.util.concurrent.*;

public class ThreadPool2 {

    /**
     * 比较Future和FutureTask的使用
     */

    public static void main(String[] args) throws ExecutionException, InterruptedException {
        ExecutorService pool = Executors.newCachedThreadPool();
        Future<String> future = pool.submit(new Callable<String>() {
            @Override
            public String call() throws Exception {
                System.out.println("future ....");
                Thread.sleep(3000);
                return "done";
            }
        }
        );
        System.out.println(future.get());
        ExecutorService threadPool = Executors.newCachedThreadPool();
        FutureTask<String> futureTask = new FutureTask<String>(new Callable() {
            @Override
            public Object call() throws Exception {
                System.out.println("futuretask ...");
                Thread.sleep(3000);
                return "done";
            }
        }
        );
//        threadPool.submit(futureTask);
        Thread thread = new Thread(futureTask);
        thread.start();
        System.out.println(futureTask.get());
    }
}
